module(..., package.seeall)

require "dialog"

local story

local function finishedWalkTransistion(obj)
	print("moving to puzzle 1")
	director:changeScene("puzzle1","moveFromRight")
end

local function closeDialog()
	dialog.close(story)
end

-- Main function - must return a display.newGroup()
function new()
	local localGroup = display.newGroup()

	--Background
	local background = display.newImage("genericbg.png", 0, 0, true)
	localGroup:insert(background)

	-- The player TODO get the player image
	local player = display.newImage("player.png")
	player.x = 245
	player.y = 280
	localGroup:insert(player)

	-- Arrows to Continue TODO get the left arrow image
	local leftArrow = display.newImage("leftarrow.png")

	local function leftArrowt ( event ) 
		-- The player moves to the right for some reason
		if event.phase == "ended" then
			print("clicked left\n")
			player.xScale = -1
			transition.to(player, {time=2000, x=0, transition=easing.outExpo, onComplete=finishedWalkTransition })
		end
	end

	leftArrow:addEventListener("touch", leftArrowt)
	leftArrowx = 24
	leftArrow.y = 180
	localGroup:insert(leftArrow)

	-- TODO get the right arrow image
	local rightArrow = display.newImage("rightarrow.png")

	local function rightArrowt (event )
		if event.phase == "ended" then
			director:changeScene("puzzle1","moveFromRight")
			--print("clicked right\n")
			--transition.to(player, {time=2000, x = 400, transition=easing.outExpo, onComplete=finishedWalkTransition })
		end
	end

	rightArrow:addEventListener("touch", rightArrowt)
	rightArrow.x = 400
	rightArrow.y = 180
	localGroup:insert(rightArrow)

	return localGroup

end

